package com.zg.autoflow.web;

import com.zg.autoflow.req.*;
import com.zg.autoflow.service.WorkflowManageService;
import com.zg.autoflow.vo.WorkflowStepDataVo;
import com.zg.autoflow.vo.WorkflowVo;
import com.zg.common.core.R;
import com.zg.common.core.dao.autoflow.entity.SettleBizform;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
* @author zg
*/
@Api(tags = {"流程流转"})
@RestController
@RequiredArgsConstructor
public class WorkflowManageController {
	private final WorkflowManageService workflowManageService;

	/**
	 * 发起流程
	 * @param startWorkflowReq
	 * @return
	 */
	@ApiOperation("发起流程")
	@PostMapping("/flow/workflowManage/startWorkflow")
	public R<WorkflowVo> startWorkflow(@RequestBody @Valid StartWorkflowReq startWorkflowReq) {
		WorkflowVo workflowVo = workflowManageService.startWorkflow(startWorkflowReq);
		return R.success(workflowVo);
	}

	@ApiOperation("提交流程")
	@PostMapping("/flow/workflowManage/submitWorkflow")
	public R<WorkflowVo> submitWorkflow(@RequestBody @Valid SubmitWorkflowReq submitWorkflowReq) {
		WorkflowVo nextWorkflowVo = workflowManageService.submitWorkflow(submitWorkflowReq);
		return R.success(nextWorkflowVo);
	}

	@ApiOperation("退回流程")
	@PostMapping("/flow/workflowManage/backWorkflow")
	public R<String> backWorkflow(@RequestBody @Valid BackWorkflowReq backWorkflowReq) {
		String result = workflowManageService.backWorkflow(backWorkflowReq);
		return R.success(result);
	}

	@ApiOperation("作废流程")
	@PostMapping("/flow/workflowManage/cancelWorkflow")
	public R<String> cancelWorkflow(@RequestBody @Valid CancelWorkflowReq cancelWorkflowReq) {
		String result = workflowManageService.cancelWorkflow(cancelWorkflowReq);
		return R.success(result);
	}

	@ApiOperation("获取流程基本信息")
	@PostMapping("/flow/workflowManage/getStepData")
	public R<WorkflowStepDataVo> getStepData(@RequestBody @Valid WorkflowStepDataReq workflowStepDataReq) {
		WorkflowStepDataVo result = workflowManageService.getStepData(workflowStepDataReq);
		return R.success(result);
	}

	@ApiOperation("保存流程基本信息")
	@PostMapping("/flow/workflowManage/saveData")
	public R<SettleBizform> saveData(@RequestBody @Valid WorkflowSaveDataReq jsonObject) {
		SettleBizform settleBizform=workflowManageService.saveData(jsonObject);
		return R.success(settleBizform);
	}

	@ApiOperation("生成文件")
	@PostMapping("/flow/workflowManage/makePdf")
	public R<SettleBizform> makePdf(@RequestBody @Valid WorkflowMakePdfReq req) {
		SettleBizform settleBizform= workflowManageService.makePdf(req);
		return R.success(settleBizform);
	}
}
